from pyramid.config import Configurator

#from .models import DBSession
from pyramid.authentication import AuthTktAuthenticationPolicy
from pyramid.authorization import ACLAuthorizationPolicy

from pyramid_beaker import session_factory_from_settings

from sqlalchemy import engine_from_config

from pdm.models import initialize_sql

def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    engine = engine_from_config(settings, 'sqlalchemy.')
    initialize_sql(engine)

    session_factory = session_factory_from_settings(settings)

    authn_policy = AuthTktAuthenticationPolicy('s0secret')
    authz_policy = ACLAuthorizationPolicy()
    
    config = Configurator(
        settings=settings,
        root_factory='pdm.models.RootFactory',
        authentication_policy=authn_policy,
        authorization_policy=authz_policy,
        session_factory=session_factory
    )
    """
    config.add_subscriber('pdm.subscribers.add_base_template',
                          'pyramid.events.BeforeRender')
    config.add_subscriber('pdm.subscribers.csrf_validation',
                          'pyramid.events.NewRequest')
	"""
    config.add_static_view('static', 'pdm:static')
    
    config.add_route('login', '/login')
    config.add_route('add_usuario', '/add_usuario')
    config.add_route('delete_usuario', '/delete_usuario')    
    config.add_route('consulta_usuario', '/consulta_usuario')
    config.add_route('registrarUsuario', '/registrarUsuario')
    config.add_route('index', '/index')
    config.add_route('home', '/')
    
    
    config.scan()
    
    return config.make_wsgi_app()

